package com.example.ex3;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class ConfigActivity extends AppCompatActivity {
    private static final String TAG = "Rate";
    private float dollar2 ;
    private float euro2;
    private float won2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_config);

        Intent intent = getIntent();
        dollar2 = intent.getFloatExtra("dollar_key",0.0f);
        euro2 = intent.getFloatExtra("euro_key",0.0f);
        won2 = intent.getFloatExtra("won_key",0.0f);

        Log.i(TAG,"onCreate:dollar2="+dollar2);
        Log.i(TAG,"onCreate:euro2="+euro2);
        Log.i(TAG,"onCreate:won2="+won2);

    }

    public void save(View btn){
        EditText input1 = findViewById(R.id.dollar2);
        String s1 = input1.getText().toString();
        if(s1.length()==0){

        }else {
            dollar2 = Float.parseFloat(s1);
        }
        EditText input2 = findViewById(R.id.euro2);
        String s2 = input2.getText().toString();
        if(s2.length()==0){

        }else {
            euro2 = Float.parseFloat(s2);
        }
        EditText input3 = findViewById(R.id.won2);
        String s3 = input3.getText().toString();
        if(s3.length()==0){

        }else {
            won2 = Float.parseFloat(s3);
        }

        Log.i(TAG,"open:save");

        Intent intent = getIntent();

        Bundle bundle = new Bundle();

        Log.i(TAG,"open:dollar"+dollar2);
        Log.i(TAG,"open:euro"+euro2);
        Log.i(TAG,"open:won"+won2);

        bundle.putFloat("dollar_key",dollar2);
        bundle.putFloat("euro_key",euro2);
        bundle.putFloat("won_key",won2);
        intent.putExtras(bundle);

        setResult(6,intent);
        finish();
        //intent2.putExtra("dollar_key",dollar2);
        //intent2.putExtra("euro_key",euro2);
        //intent2.putExtra("won_key",won2);


        //startActivity(intent2);


    }
}